package com.aepryus.loom;

import java.util.*;
import javax.servlet.http.*;

public abstract class Action implements Entry {
	private static Random random = new Random();

	private Long xid;

	public abstract String getName();
	public abstract Object process (Map<String,String> parameters,HttpServletRequest request) throws PersistenceException,ValidationException;

	public Action () {
		xid = random.nextLong();
	}
	public Action (Long xid) {
		this.xid = xid;
	}

	Long getXID () {return xid;}

	public Object doProcess (HttpServletRequest request) throws PersistenceException,ValidationException {
		Map<String,String> parameters = new HashMap<String,String>();
		// Checking for request != null in case of AutoExec function.  This may be indicative of a need
		// to revisit the AutoExec mechanism for possible reenginnering.
		if (request != null) {
			for (Enumeration e = request.getParameterNames();e.hasMoreElements();) {
				String name = (String)e.nextElement();
				parameters.put(name,request.getParameter(name));
			}
		}
		return doProcess(parameters,request);
	}
	public Object doProcess (Map<String,String> parameters,HttpServletRequest request) throws PersistenceException,ValidationException {
		return process(parameters,request);
	}
}

